package com.taillive.commons;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Random;

public class NumberUtils {

	public static double round(double d, int precision) {
		BigDecimal i = new BigDecimal(String.valueOf(d)).setScale(precision,BigDecimal.ROUND_HALF_UP);
		return i.doubleValue();
	}

	public static String format(String s, String f) {
		DecimalFormat df = new DecimalFormat(f);
		return df.format(s);
	}

	public static String format(double s, String f) {
		DecimalFormat df = new DecimalFormat(f);
		return df.format(s);
	}

	public static void main(String args[]) {

		System.out.println(round(1.575,2));
		System.out.println(format(1.575,"#.00"));
	}

}
